/**
 * @author Phuc "Noel" Vo
 */
package com.example.noelwhereismystuffs.presenters;

import android.content.Context;
import android.util.Log;

import com.example.noelwhereismystuffs.models.ISignInModel;
import com.example.noelwhereismystuffs.models.User;
import com.example.noelwhereismystuffs.views.SignInActivity.ISignInView;

public class SignInPresenter {

	private ISignInView myView;
	private ISignInModel myModel;
	private Context myContext;
	private User myUser = User.NULL_USER;
	private static final String TRUE = "true";
	private static final String FALSE = "false";
	private static final String LOCKACCOUNT = "lockAcount";
	private static final String ADMIN = "admin";
	private static final String NOACCOUNT = "noaccount";

	public SignInPresenter(ISignInView view, ISignInModel model) {
		myView = view;
		myModel = model;
//		myContext = context;
	}

	/**
	 * Send info to the model to execute sign in task
	 * 
	 * @param email
	 * @param password
	 */
	public void onSignInClick(String email, String password) {
		Log.d("Presenter", "Siginning");
		String res = myModel.signIn(email, password);
		myUser = myModel.getUser(email);
		if (res.equals(TRUE)) {
			myView.setUser(myUser);
			myView.advanceLogin();
		} else if (res.equals(LOCKACCOUNT)) {
			myView.advanceLockEmail();
		} else if (res.equals(ADMIN)) {
			myView.advanceAdminLogin();
		} else if (res.equals(NOACCOUNT)) {
			myView.advanceNoAccount();
		} else if (res.equals(FALSE)) {
			myView.advanceFalse();
		}

	}

	/**
	 * Tell the view to go to Register Activity
	 */
	public void onRegisterClick() {
		myView.advanceRegister();
	}
}
